import {Injectable} from '@angular/core';
import {Hero} from './hero';

const HEROS: Hero[] = [
  {id: '1', name: '卡特琳娜'},
  {id: '2', name: '卡萨丁'},
  {id: '3', name: '亚索'},
  {id: '4', name: '泰隆'},
  {id: '5', name: '乐芙兰'},
  {id: '6', name: '劫'},
  {id: '7', name: '弗拉基米尔'}
];

@Injectable()
export class HeroService {
  getHero(id: string): Promise<Hero> {
    return this.getHeroes()
      .then(heroes => heroes.find(hero => hero.id === id));
  }

  getHeroes(): Promise<Hero[]> {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve(HEROS);
      }, 1000);
    });
  }
}
